<?php

require_once('config.php');
require_once('class/cruds.php');

if(isset($_GET['params'])){

$params = $_GET['params'];

$params_explode = explode(',', $params, -1);

$where_kop_arr = "";
$where_kota_arr = "";

$arr_tmp = explode("-", $params_explode[0]);

for($i=0; $i<count($params_explode); $i++){
	$arr_tmp = explode("-", $params_explode[$i]);
	
	
	if($arr_tmp[0] == "NAMAKOTA"){
		if($where_kota_arr != "") $where_kota_arr .= " AND ";
		$where_kota_arr .= $arr_tmp[0]." LIKE '%".$arr_tmp[1]."%'";//echo $where_kota_arr;
		
	} else {
		if($where_kop_arr != "") $where_kop_arr .= " AND ";
		$where_kop_arr .= $arr_tmp[0]." LIKE '%".$arr_tmp[1]."%'";
		
	}
	
	/* $arr_tmp2 = array(
		'key' => $arr_tmp[0],
		'value' => $arr_tmp[1]
	);
	$params_arr[] = $arr_tmp2; */
} 

$cruds = new CRUDS();
$cruds->select('*');
$cruds->from('koperasi');
if($where_kota_arr == "") $cruds->where($where_kop_arr);
else $cruds->where($where_kop_arr.' AND '.$where_kota_arr);
$cruds->inner_join('kota', 'kota.IDKOTA = koperasi.IDKOTA');
$cruds->join('provinsi', 'kota.IDPROPINSI = provinsi.IDPROPINSI');

}

else {

$cruds = new CRUDS();
$cruds->select('*');
$cruds->from('koperasi');
$cruds->inner_join('kota', 'kota.IDKOTA = koperasi.IDKOTA');
$cruds->join('provinsi', 'kota.IDPROPINSI = provinsi.IDPROPINSI');

}

$params_arr = array();
$cruds_result = $cruds->get();
//echo $cruds_result;

while($row = mysql_fetch_array($cruds_result)){
	$param_temp = array(
		'nama_kop' => $row['NAMAKOPERASI'],
		'no_telp' => $row['NOTELP'],
		'no_fax' => $row['NOFAX'],
		'tgl_berdiri' => $row['TGLBERDIRI'],
		'info' => $row['INFORMASI'],
		'kota' => $row['NAMAKOTA'],
		'prov' => $row['NAMAPROPINSI'],
		'kode_telp' => $row['KODETELP']
	);
	$params_arr[] = $param_temp;
}

include($_SERVER['DOCUMENT_ROOT'].'/incofarming/Views/cari-koperasi/search-koperasi-result_view.php');

?>